<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/html">
<head>
    <meta charset="utf-8">
    <title>协会概况</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="${ctxPath}/static/manage/css/x-admin.css" media="all">
    <link rel="stylesheet" href="${ctxPath}/static/manage/layui/css/layui.css" media="all">
    <script src="${ctxPath}/static/manage/layui/layui.js"></script>
    <script src="${ctxPath}/static/manage/js/jquery.js"></script>
</head>
<body>
<div class="x-nav">
        <span class="nav-breadcrumb">
            <a><cite>后台管理></cite></a>
            <a><cite>投诉管理></cite></a>
            <a><cite>投诉信息</cite></a>
        </span>
</div>
<div class="x-body">
    <blockquote class="layui-elem-quote quoteBox">
        <div class="layui-inline">
            <div class="layui-input-inline">
                <input type="text" class="layui-input searchContent" placeholder="请输入投诉内容关键字" />
            </div>
            <a class="layui-btn search_btn layui-icon" data-type="reload">&#xe615;搜索</a>
        </div>
        <input id="addBtn"  class="layui-btn layui-btn-normal layui-icon" type="button" value="&#xe654;添加" onclick="addComplainBtn()">
        <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"  href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon" style="line-height:30px">ဂ</i></a>
    </blockquote>
    <table id="complainTable" lay-filter="complainTable"></table>
</div>
</body>
</html>

<script type="text/javascript">
    var tabObj;
    layui.use(['jquery', 'table', 'layer', 'util'], function(){
        var $ = layui.$, table = layui.table, layer = layui.layer, util = layui.util;

        var active = {
            reload: function(){
                table.reload('search_table_id', {
                    where: {
                        complaintsContent: $('.searchContent').val(),
                        page: 1
                    }
                });
            }
        };

        tabObj= table.render({
            elem: '#complainTable'
            ,id: 'search_table_id'
            ,height: 550
            ,url: 'complaints/complainTable'
            ,page: true
            ,limit: 10
            ,cols: [[
                { checkbox: true, fixed: true },
                { field: 'id', title: '序号', width:150, sort: true, fixed: true },
                { field: 'userName', title: '用户名', width:150, sort: true },
                { field: 'name', title: '投诉类型', width:150},
                { field: 'complaintsContent', title: '投诉内容', width:150},
                { field: 'createTime', title: '投诉时间', width:200, sort: true, templet: function (d){
                        return util.toDateString(d.createTime);
                    }},
                { field: 'img', title: '图片', width:100, sort: true, templet: function (d){
                        return '<img src="'+d.img+'" style="width: 50px;height: 50px" onclick="showImg(this)"  pcid="'+ d.id + '"';
                    }},
                { field: 'tempId', title: '操作', width:260, templet: function(d){
                        return '<a class="layui-btn layui-btn-xs" lay-event="read" lay-id="'+ d.tempId +'"><i class="layui-icon layui-icon-read"></i>查看</a>' +
                            '<a class="layui-btn layui-btn-xs" lay-event="edit" lay-id="'+ d.tempId +'"><i class="layui-icon layui-icon-edit"></i>编辑</a>'+
                            '<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" lay-id="'+ d.tempId +'"><i class="layui-icon layui-icon-delete"></i>删除</a>';
                    }}
            ]]
        });

        // 搜索（利用定义的active重新载入表格）
        $('.search_btn').on('click', function(){
            if($('.searchContent').val()!=""){
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            }else{
                tabObj.reload();
            }
        });

        // 监听工具条
        table.on('tool(complainTable)', function (obj) {
            // data当前行数据， lay-event或event 对应的值，当前行tr的DOM对象
            var data = obj.data, event = obj.event;
            console.log(data);
            switch(event){
                case "read":
                    complainRead(data);
                    break;
                case "edit":
                    complainUpdate(data);
                    break;
                case "del":
                    complainDel(data);
                    break;
            }
        });
        //删除
        function complainDel(rowData) {
            var id = rowData.id;
            layer.confirm("确认删除该投诉信息吗",{icon: 3, title:'提示'},function () {
                layer.closeAll();
                $.ajax({
                    url:'complaints/toComplainDel',
                    data:{
                        id:id
                    },
                    type:'post',
                    success:function (res) {
                        alert(res);
                        layer.closeAll();
                        tabObj.reload();
                    },
                    error:function (res){
                        alert(res);
                        layer.closeAll();
                        tabObj.reload();
                    }
                })
            })
        }
        // 查看
        function complainRead(rowData) {
           //alert(rowData.id)
            layer.open({
                title : "查看投诉详情",
                type : 2,
                fix: false, //不固定
                maxmin: true,
                area: ['600px', '400px'],
                content: "complaints/toComplainRead/" + rowData.id
            });
        }

        // 编辑
        function complainUpdate(rowData) {
            layer.open({
                title : "编辑投诉信息",
                type : 2,
                fix: false, //不固定
                maxmin: true,
                area: ['600px', '400px'],
                content: "complaints/toComplainUpdate/" + rowData.id
            });
        }

    });
   //添加按钮
    function addComplainBtn(){
        layer.open({
            title : "添加投诉信息",
            type : 2,
            fix: false, //不固定
            maxmin: true,
            area: ['600px', '400px'],
            content: "complaints/toComplainAdd"
        })
    }

    //图片显示
    function showImg(obj) {
        var $ = layui.$;
        var id = $(obj).attr("pcid");
        layui.use("layer", function() {
            var layer = layui.layer;
            layer.open({
                type : 2,
                title : "修改图片",
                area : [ '400px', '400px' ],
                content : "complaints/uploadImg/"+id
            })
        })
    }
</script>
